// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import gameData from "./gameData";
// import sceneMediator from "../resources/framework/sceneMediator";
import array = cc.js.array;
import sceneMediator from "../framework/sceneMediator";

const {ccclass, property} = cc._decorator;

@ccclass
export default class pumpkinMediator extends cc.Component {

    @property()
    index : number = 0;

    @property()
    specialLevel5  = false;

    onLoad(){
        if(this.specialLevel5){
            this.node.active = gameData.appleGetList[this.index] == 1 ?  false : true;
        }else{
            if(sceneMediator.curEnterLevel == 0){
                if(sceneMediator.getShowScene() == 24) return;
                let data = gameData.getPumpkinShowDate()[sceneMediator.getShowScene() - 1];
                if(data[this.index] == 0){
                    this.node.active = false;
                }
            }else{
                let data = gameData.getPumpkinShowDate()[50 + sceneMediator.princeShowLevel - 1];
                if(data[this.index] == 0){
                    this.node.active = false;
                }
            }
        }
    }

    setPumpkinShowState(){

        if(this.specialLevel5){
            gameData.appleGetList[this.index] = 1;
            gameData.saveOtherGameData();
        }else{
            if(sceneMediator.curEnterLevel == 0){
                let data = gameData.getPumpkinShowDate()[sceneMediator.getShowScene() - 1];
                if(data.length > 0){
                    if(sceneMediator.getShowScene() == 24){
                        gameData.getPumpkinShowDate()[sceneMediator.getShowScene() - 1][this.index] = 0;
                        gameData.savePumpkinShowDate();
                    }else{
                        gameData.getPumpkinShowDate()[sceneMediator.getShowScene() - 1][this.index] = 0;
                        gameData.savePumpkinShowDate();
                    }
                }
            }else{
                let data = gameData.getPumpkinShowDate()[50 + sceneMediator.princeShowLevel - 1];
                if(data.length > 0){
                    gameData.getPumpkinShowDate()[50 + sceneMediator.princeShowLevel - 1][this.index] = 0;
                    gameData.savePumpkinShowDate();
                }
            }
        }
    }
}
